import yaml
from pathlib import Path


def read_config(environment="dev"):
    """根据环境变量读取配置文件"""
    config_file = Path(__file__).parent / f"{environment}.yaml"
    try:
        with open(config_file, "r") as file:
            config = yaml.safe_load(file)
    except FileNotFoundError:
        raise ValueError(f"Configuration file for environment '{environment}' not found.")
    except yaml.YAMLError as e:
        raise ValueError(f"Error parsing YAML file for environment '{environment}': {e}")
    return config
